package com.jsg.sl651.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 遥测站分类
 */
@Getter
@AllArgsConstructor
public enum ClassificationOfStations {
    precipitation((byte) 0x50, (byte) 'P', "降水", "降水/蒸发/气象"),
    riverway((byte) 0x48, (byte)'H', "河道","降水/蒸发/气象/河道水情/水质"),
    reservoir((byte) 0x4B, (byte)'K', "水库（湖泊）","降水/蒸发/气象/水库（湖泊）水情/水质"),
    gate_dam((byte) 0x5A, (byte)'Z', "闸坝","降水/蒸发/气象/闸坝水情/水质"),
    pump_station((byte) 0x44, (byte)'D', "泵站","降水/蒸发/气象/泵站水情/水质"),
    tide((byte) 0x54, (byte)'T', "潮汐","降水/蒸发/气象/潮汐水情"),
    soil_moisture_content((byte) 0x4D, (byte)'M', "墒情","降水/蒸发/墒情"),
    groundwater((byte) 0x47, (byte)'G', "地下水","埋深/水质/开采量"),
    water_quality((byte) 0x51, (byte)'Q', "水质","水质/流量/水位"),
    water_intake((byte) 0x49, (byte)'I', "取水口","水质/水位/水量/水压/.."),
    drain_outlet((byte) 0x4F, (byte)'O', "排水口","水质/水位/水量/水压/.."),
    other((byte) 0x4E, (byte)'N', "其他","其他"),
    ;
    private final byte hex;
    private final byte ascii;
    private final String name;
    private final String desc;


    public static ClassificationOfStations getByCode(CommunicationMessageType type, byte code) {
        if (type == CommunicationMessageType.HEX) {
            for (ClassificationOfStations classificationOfStations : values()) {
                if (classificationOfStations.hex == code) {
                    return classificationOfStations;
                }
            }
        } else if (type == CommunicationMessageType.ASCII) {
            for (ClassificationOfStations classificationOfStations : values()) {
                if (classificationOfStations.ascii == code) {
                    return classificationOfStations;
                }
            }
        }
        return other;
    }

}
